/* function getOs(){
	if(navigator.userAgent.indexOf("MSIE")>0)return 1;
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
	if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3;   
	if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4;
	if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5;
	return 0;
}

function pre_IMG(IMG_u,DIV_u,DIV_w,DIV_h,Kk){ 
	if( !IMG_u.value.match( /.jpg|.gif|.png/i ) ){        
		alert('图片格式无效！');        
		return false;
    } 

	if (getOs()==1){
		// var IMG = IMG_u.value;
		IMG_u.select();
		IMG = document.selection.createRange().text; 
		
		DIV_u.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);";
		DIV_u.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = IMG;    
		DIV_u.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";    
		IMG_go(DIV_u,DIV_w,DIV_h,Kk);
	}else if(getOs()==2){
		var objPreview=arguments[5] ? arguments[5] : document.getElementById("img_pre");
		objPreview.style.display = 'block';

	//	查看对象属性
	//	var tt1=document.getElementById("test1");  	 
	//	for(i in IMG_u.files[0]){
	//	   tt1.innerHTML+=i+":"+IMG_u.files[0][i]+"<br />";     
	//	}
			
		objPreview.style.width = DIV_w+"px";        
		objPreview.style.height = 'auto';

		var objectURL = window.URL.createObjectURL(IMG_u.files[0]); 
		//alert(IMG_u.files[0].getAsDataURL());         
		objPreview.src = objectURL;
		//alert(objPreview.width);
	}else{
		return false;
	}
}
   
function IMG_go(DIV_u2,DIV_w,DIV_h,Kk){    
	DIV_u2.style.visibility = "visible";
	if (Kk!=1){
		DIV_u2_W=DIV_u2.offsetWidth;    
		DIV_u2_H=DIV_u2.offsetHeight;    

		DIV_u2_width=DIV_w;  
		DIV_u2_height=DIV_h;     
   
   
		if(DIV_u2_W <DIV_u2_width && DIV_u2_H <DIV_u2_height){    
			DIV_u2.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";    
			return;             
		}else{    
			DIV_u2.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale";    
		}    
		H1 = DIV_u2_height/DIV_u2_H;    
		W1 = DIV_u2_width/DIV_u2_W;
		if(H1<W1) Rate=H1;    
		else Rate=W1;             
		DIV_u2_W = DIV_u2_W * Rate;    
		DIV_u2_H = DIV_u2_H * Rate;    
		DIV_u2.style.width = DIV_u2_W;    
		DIV_u2.style.height = DIV_u2_H;  
	}else{
		DIV_u2.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale";    
		DIV_u2.style.width = DIV_w;    
		DIV_u2.style.height = DIV_h; 
        return; 		 
	}
} */
function pre_IMG(obj,newPreview,w,h,imgHeadPhoto){
    var allowSuffix=".jpg,.gif,.png";//.jpg,.bmp,.gif,.png,允许上传文件的后缀名
    var suffix=obj.value.substring(obj.value.lastIndexOf(".")+1).toLowerCase();            
    var browserVersion= window.navigator.userAgent.toUpperCase();//浏览器版本信息  
	!imgHeadPhoto && (imgHeadPhoto=$("#img_pre"));

    if(allowSuffix.indexOf(suffix)>-1){               
        if (window.navigator.appName=="Microsoft Internet Explorer"){//ie浏览器
            if(browserVersion.indexOf("MSIE 6.0")>-1){//ie6
                imgHeadPhoto.attr("src",obj.value);
            }else{//ie7、ie8、ie9未测试
                //滤镜实现
				obj.select();
            //	var newPreview =document.getElementById("divNewPreview");
                if(newPreview==null){
					newPreview =document.createElement("div");
					imgHeadPhoto.after(newPreview);
				//	newPreview.setAttribute("id","divNewPreview");
				//	newPreview.style.border="solid 1px #d2e2e2";
                }
				
                newPreview.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src='" + document.selection.createRange().text + "')";
				newPreview.style.width = w;
				newPreview.style.height = h;
			//	$("#divPreview").attr("style","display:none");
            //	$("#divPreview").after(newPreview);
            }
        }else{
			if(browserVersion.indexOf("FIREFOX")>-1){ //火狐浏览器
				var firefoxVersion= parseFloat(window.navigator.userAgent.toLowerCase().match(/firefox\/([\d.]+)/)[1]);
				if(firefoxVersion<7){//firefox7.0以下版本
					imgHeadPhoto.attr("src", obj.files[0].getAsDataURL());
				}else{//火狐7.0以上版本
					imgHeadPhoto.attr("src", window.URL.createObjectURL(obj.files[0]));
				}
			}else if(obj.files){
				//兼容chrome等，也可以兼容火狐，通过HTML5来获取路径                   
				if(typeof FileReader !== "undefined"){
					var reader = new FileReader(); 
					reader.onload = function(e){imgHeadPhoto.attr("src",e.target.result);}  
					reader.readAsDataURL(obj.files[0]);
				}else if($.browser.safari){
					alert("暂时不支持Safari浏览器!");
				}
			}else{
				imgHeadPhoto.attr("src",obj.value);//其他
			}
			
			imgHeadPhoto.attr({"width":w,"height":h}).show();
			if(w=="auto"){
				imgHeadPhoto.css("width",w);
			}
			if(h=="auto"){
				imgHeadPhoto.css("height",h);
			}
		}
    }else{
        alert("仅支持"+allowSuffix+"为后缀名的文件!");   
        //清空选中文件           
        obj.value="";
        if(window.navigator.appName=="Microsoft Internet Explorer"){                        
            obj.select();
            document.selection.clear();
        }                
        obj.outerHTML=obj.outerHTML;
    }
}